<%--
  Created by IntelliJ IDEA.
  User: JY
  Date: 2022/1/7
  Time: 11:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>设计组成</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
    <style>
        #xxT{
            display: none;
        }
    </style>
</head>
<body>
<span style="color: blue;font-family:华文宋体"><marquee width=400 direction=left align=middle><span>您正在做的业务是：产品设计--产品档案管理--制定物料组成设计单</span></marquee></span>
<div class="row" style="margin-top: 20px;padding-left: 100px"  id="div1">
    <table id="table" class="table table-hover table-bordered" style="width: 1100px">
        <thead>
        <tr align="center">
            <th>产品编号</th>
            <th>产品名称</th>
            <th>用途类型</th>
            <th>I级分类</th>
            <th>II级分类</th>
            <th>III级分类</th>
            <th>产品经理</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
    </table>
</div>
<DIV class=DIV_STYLE2 style="display: none" id="div2"><TABLE cellSpacing=0 cellPadding=0 width=1000 align=center bgColor=#ffffff border=0 >
    <div style="position: relative;left: 60%">

        <INPUT   data-toggle="modal" data-target="#myModal"  type=button value=添加物料>
        <INPUT  onclick=delSelect() type=button value=删除物料>
        <INPUT onclick="yuelan()" type=submit value=预览>
        <INPUT onmouseup="this.className='btn3_mouseup'" onclick=fanhui() onmouseover="this.className='btn3_mouseover'" onmousedown="this.className='btn3_mousedown'" onmouseout="this.className='btn3_mouseout'" class=btn3_mouseout type=button value=返回>
        <INPUT id="xxT" onclick="tijiao()" type=button value=确定>
    </div>
    <TBODY>
    <TR>
        <TD class=TABLE_STYLE6 vAlign=bottom rowSpan=2 align=center>
            <TABLE style="BORDER-TOP: #333333 1px solid; BORDER-RIGHT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid; BORDER-LEFT: #333333 1px solid" cellSpacing=0 cellPadding=0 width="100%" border=0>
                <TBODY>
                <TR>
                    <TD height=10 colSpan=4>
                        <TABLE width="100%">
                            <TBODY>
                            <TR>
                                <TD>
                                    <table align="center">
                                        <tr>
                                            <td><h3>物料工序设计单</h3></td>
                                        </tr>
                                    </table>
                                    <br>
                                    <div>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span>产品名称:</span>
                                        <span id="cpmc"></span>
                                        <span style="position: relative;left:500px;">产品编号:<span id="cpbh"></span></span>
                                        <br>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span>设计人:<input style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none" id="sjr"></span>
                                    </div>
                                    <br>
                                    <TABLE id=tableOnlineEdit class=TABLE_STYLE5 borderColor=#000000 cellSpacing=0 cols=1 borderColorDark=#eeeeee cellPadding=0 align=center borderColorLight=#848284 border=1><THEAD>
                                    <TR class=TR_STYLE2 height="10" bgColor=#d2e9ff>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="7%" align=left>点选</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>物料编号</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>物料名称</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="7%" align=left>用途</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>数量</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>单位</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="19%" align=left>计划成本单价</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="22%" align=left>小计(元)</TD></TR>
                                    <%--                                    <TR class=TR_STYLE1  height=20>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT id=checkLine class=CHECKBOX_STYLE1 type=checkbox value=on name=checkbox></TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT onfocus=this.blur() class=INPUT_STYLE4 name=procedure_name>fds</TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT onfocus=this.blur() class=INPUT_STYLE4 name=procedure_ID>fds</TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><SPAN style="WIDTH: 120px; BACKGROUND: #ffffff" name="product_describe_ok"></SPAN><INPUT onfocus=this.blur() class=INPUT_STYLE4 type=hidden name=procedure_describe></TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT class=INPUT_STYLE5 name=labour_hour_amount></TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT class=INPUT_STYLE5 name=amount_unit></TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left><INPUT class=INPUT_STYLE5 name=cost_price></TD>--%>
                                    <%--                                        <TD class=TD_STYLE2 borderColor=#dedbd6 align=left>&nbsp;</TD></TR>
                                                --%>
                                    </THEAD>
                                    </TABLE>
                                    <br>
                                    <div>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span>登记人:<input style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none" value="${login_id}" id="djr"></span>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <span style="position: relative;left:200px;">登记时间:<span id="shijian"></span></span>
                                    </div>
                                    <br>

                                    <div>
                                        <div>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <span style="position: relative;top: -40px">设计要求:</span><textarea style="resize: none" rows=4 cols="100" id="sjyq"></textarea>
                                        </div>
                                    </div>
                                </TD></TR></TBODY></TABLE></TD></TR>
                <TR>
                    <TD width=56 colSpan=3 noWrap></TD></TR>
                <TR>
                    <TD height=100 colSpan=3 noWrap></TD>
                    <TD></TD></TR>
                <TR vAlign=bottom>
                    <TD colSpan=4 noWrap align=center></TD></TR></TD>
                <TR>
                    <TD colSpan=4 noWrap align=right></TD></TR></TBODY></TABLE></TD>
        <TD bgColor=#ffffff height=2 width=1></TD>
        <TD bgColor=#ffffff height=2 width=1></TD>
        <TD bgColor=#ffffff height=2 width=1></TD></TR>
    <TR>
        <TD bgColor=#333333 height=120 width=1></TD>
        <TD bgColor=#666666 height=120 width=1></TD>
        <TD bgColor=#999999 height=120 width=1></TD></TR>
    <TR align=right vAlign=top>
        <TD colSpan=4>
            <TABLE class=TABLE_STYLE6 cellSpacing=0 cellPadding=0 align=center border=0>
                <TBODY>
                <TR>
                    <TD bgColor=#333333 height=1></TD></TR>
                <TR>
                    <TD bgColor=#666666 height=1></TD></TR>
                <TR>
                    <TD bgColor=#999999 height=1></TD></TR></TBODY></TABLE></TD></TR>
    <TR align=right vAlign=middle>
        <TD colSpan=4></TD></TR></TBODY></TABLE></DIV>
<div class="modal fade" id="myModal"style="width: 1000px">
    <div class="modal-dialog">
        <div class="modal-content">
           <!-- 模态框头部 -->
            <div class="modal-header" width="1000px">
                <h4 class="modal-title">添加物料</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body" width="1000px">
                <table border="1px" cellspacing="0" cellpadding="0" width="2000px" id="wl">
                    <tr align="center">
                        <th>物料编号</th>
                       <%-- <th>物料名称</th>--%>
                        <th>用途</th>
                       <%-- <th>物料描述</th>
                        <th>单位</th>--%>
                        <th>计划成本单价</th>
                        <th>添加</th>
                    </tr>
                </table>
            </div>

           <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
</body>
<script src="/js/bootstrap-table-zh-CN.min.js"></script>
<script src="/js/jquery.form.js"></script>
<script src="/js/jquery.serializejson.js"></script>

<script>
    jiazai()
    /*查询所有商品*/
    function jiazai() {
        $("#table").bootstrapTable({
            method: "post",
            contentType: "application/json",
            url: "/dfile/chafood",
            striped: true,
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 2,
            pageList: [2, 4, 6, 8],
            queryParams: function (param) {
                return {
                    page: (param.offset / param.limit) + 1,
                    num: param.limit,
                }
            },
            columns: [
                {title: "产品编号", field: "productId", align: "center"},
                {title: "产品名称", field: "productName", align: "center"},
                {
                    title: "用途类型", field: "type", align: "center",
                    formatter: function (value, row, index) {
                        var type;
                        if (row.type == "Y001-1") {
                            type = "商品";
                        } else if (row.type == "Y001-2") {
                            type = "物料";
                        }
                        return type;
                    }
                },
                {title: "I级分类", field: "firstKindName", align: "center"},
                {title: "II级分类", field: "secondKindName", align: "center"},
                {title: "III级分类", field: "thirdKindName", align: "center"},
                {title: "产品经理", field: "responsiblePerson", align: "center"},
                {
                    title: "操作", field: "id", align: "center",
                    formatter: function (value, row, index) {
                        console.log(row)
                        var btn1 = "<button class='btn btn-primary btn-sm' onclick=\"href(" + row.productId + ")\">制定设计单</button>";
                        return btn1
                    }
                }
            ]
        })
        $("#submit_select").click(function () {
            $("#table").bootstrapTable("refresh");
        })
    }

    /*根据编号拿到里面所对应的值并赋值给到相关的控件中*/
    function href(id) {
        document.getElementById("div1").style.display='none'
        document.getElementById("div2").style.display='block'
        var myDate = new Date();
        year = myDate.getYear()+1900;
        month = myDate.getMonth()+1;
        date = myDate.getDate();
        hour = myDate.getHours();
        minute =myDate.getMinutes();
        second = myDate.getSeconds();
        $.ajax({
            type:"get",
            url:"/dfile/xx/"+id,
            dataType:"json",
            success:function (data) {
                console.log("xxxx")
                console.log(data)
                    document.getElementById("cpmc").innerText = data.productName
                    document.getElementById("cpbh").innerText = data.productId
                    document.getElementById("shijian").innerText = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
            }
        })
    }
    /*查询所有物料并不包括添加的商品*/
    wl()
    function wl() {
        $("#wl").bootstrapTable({
            method: "post",
            contentType: "application/json",
            url: "/dfile/chawl",
            striped: true,
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 2,
            pageList: [2, 4, 6, 8],
            queryParams: function (param) {
                return {
                    page: (param.offset / param.limit) + 1,
                    num: param.limit,
                }
            },
            columns: [
                {title: "物料编号", field: "productId", align: "center"},
               /* {title: "物料名称", field: "productName", align: "center"},*/
                {
                    title: "用途类型", field: "type", align: "center",
                    formatter: function (value, row, index) {
                        var type;
                        if (row.type == "Y001-1") {
                            type = "商品";
                        } else if (row.type == "Y001-2") {
                            type = "物料";
                        }
                        return type;
                    }
                },
                /*{title: "物料描述", field: "productDescribe", align: "center"},
                {title: "单位", field: "personalUnit", align: "center"},*/
                {title: "计划成本单价", field: "costPrice", align: "center"},
                {
                    title: "操作", field: "id", align: "center",
                    formatter: function (value, row, index) {
                        console.log(row)
                        var btn1 = "<a href='#' id='fq' onclick='bztj("+row.productId+","+JSON.stringify(row)+")'>添加</a></Td>"
                        return btn1;
                    }
                }
            ]
        })
        $("#submit_select").click(function () {
            $("#table").bootstrapTable("refresh");
        })
    }

    /*模态框添加物料*/
    function bztj(productId,it) {
        var type=""
        if (it.type == "Y001-1") {
            type = "商品";
        } else if (it.type == "Y001-2") {
            type = "物料";
        }
            document.getElementById("tableOnlineEdit").innerHTML+="<tr>" +
                "<td><input type='checkbox' name='car'/></td>" +
                "<td><input type='hidden' class='id' value="+it.productId+">"+it.productId+"</td>" +
                "<td><input type='hidden' class='name' value="+it.productName+">"+it.productName+"</td>" +
                "<td><input type='hidden' class='type' value="+type+">"+type+"</td>" +
                "<td><input type='text' class='shuliang'/></td>" +
                "<td><input type='hidden' class='dw' value='个'/>个</td>" +
                "<td><input type='hidden' class='pp' value="+it.costPrice+">"+it.costPrice+"</td>" +
               "<td><input type='text' value='' class='xiaoji' id='jieguo' readonly='readonly'></td>" +
                "</tr>"
    }

    //模态框删除物料
    function delSelect() {
        let car = document.getElementsByName("car");
        for(let i=car.length-1;i>=0;i--){
            if (car[i].checked==true){
                car[i].parentNode.parentNode.parentNode.remove();
            }
        }
    }

    /*预览则是计算单价并显示在表格中*/
    function yuelan() {
        let nodeListOf = document.getElementById("tableOnlineEdit").querySelectorAll("tr");
        for (let i = 0; i < nodeListOf.length - 1; i++) {
            let nodeListOf1 = nodeListOf[i + 1].querySelectorAll("td");
            let a = nodeListOf1[nodeListOf1.length - 4].querySelectorAll("input")[0].value;
            let b = nodeListOf1[nodeListOf1.length - 2].innerText
            let c = a * b;
            nodeListOf1[nodeListOf1.length - 1].querySelectorAll("input")[0].value = c;
        }
        /*隐藏确认按钮*/
        document.getElementById("xxT").style.display="block";
    }

    /*批量添加到两个表中*/
    function tijiao() {
            let cpbh = document.getElementById("cpbh").innerText;
            let procedureName=document.getElementById("cpmc").innerText;
            let parentId=document.getElementById("cpbh").innerText;
            let designer=document.getElementById("sjr").innerText;
            let register= document.getElementById("djr").value;
            let  registerTime=document.getElementById("shijian").innerText;
            let  moduleDescribe=document.getElementById("sjyq").innerText;
            let xiaoji=$(".xiaoji").val();

        $.post("http://localhost:8080/wl/addDmodule",{procedureName:procedureName,parentId:parentId,
            designer:designer,register:register,registerTime:registerTime,moduleDescribe:moduleDescribe
            ,cpbh:cpbh,xiaoji:xiaoji},function (data) {

        })
      /*  let nodeListOf = document.getElementById("tableOnlineEdit").querySelectorAll("tr");
        for(let i=0;i<nodeListOf.length;i++){
            for(let j=0;j<nodeListOf[i].querySelectorAll("td").length;j++){
                console.log("xxxx"+nodeListOf[i].querySelectorAll("td")[j+1].innerHTML)
            }
        }*/
       /* let  = document.getElementById("wl").row.length-1;*/
        /*明细表添加*/
        let aa = document.getElementById("tableOnlineEdit").querySelectorAll("tr");
        for(var i =0;i<aa.length-1;i++){
            let bh = document.getElementsByClassName("id")[i].value;
            let name = document.getElementsByClassName("name")[i].value;
            let type = document.getElementsByClassName("type")[i].value;
            let shuliang = document.getElementsByClassName("shuliang")[i].value;
            let dw = document.getElementsByClassName("dw")[i].value;
            let pp = document.getElementsByClassName("pp")[i].value;
            let xiaoji = document.getElementsByClassName("xiaoji")[i].value;
            $.post("http://localhost:8080/wl/addDModuleDetails",{bh:bh,name:name,type:type,shuliang:shuliang,dw:dw,pp:pp,xiaoji:xiaoji,cpbh:cpbh},function (data) {

            })
        }
        /*修改设计单状态*/
      var productId= document.getElementById("cpbh").innerText;
        $.getJSON("http://localhost:8080/dfile/upsjd",{productId:productId},function (data) {
            if(data>0){
                document.location="sjzc.jsp"
            }

        })
    }
</script>

</html>
